//Design By Do Trung --- Email : trungqn19852003@yahoo.com
//Ngày Design :5/4/2011 5:00:13 PM
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Linq;
using System.Collections.Generic;
 
	/// <summary>
	/// </summary>
	public class BinhLuan_DA
	{
		public BinhLuan_DA() {}
#region 'Variables And Properties'
		 private int int_IdBinhLuan ;
		 public int IdBinhLuan
			{
			 get 	
				{
					 return this.int_IdBinhLuan;
				}
			 set 	
				{
					int_IdBinhLuan=value;
				}
			}
		 private int int_IdTinTuc ;
		 public int IdTinTuc
			{
			 get 	
				{
					 return this.int_IdTinTuc;
				}
			 set 	
				{
					int_IdTinTuc=value;
				}
			}
		 private string string_TieuDe ;
		 public string TieuDe
			{
			 get 	
				{
					 return this.string_TieuDe;
				}
			 set 	
				{
					string_TieuDe=value;
				}
			}
		 private string string_TenDayDu ;
		 public string TenDayDu
			{
			 get 	
				{
					 return this.string_TenDayDu;
				}
			 set 	
				{
					string_TenDayDu=value;
				}
			}
		 private string string_Email ;
		 public string Email
			{
			 get 	
				{
					 return this.string_Email;
				}
			 set 	
				{
					string_Email=value;
				}
			}
		 private string string_NoiDung ;
		 public string NoiDung
			{
			 get 	
				{
					 return this.string_NoiDung;
				}
			 set 	
				{
					string_NoiDung=value;
				}
			}
		 private DateTime DateTime_NgayTao ;
		 public DateTime NgayTao
			{
			 get 	
				{
					 return this.DateTime_NgayTao;
				}
			 set 	
				{
					DateTime_NgayTao=value;
				}
			}
		 private bool bool_TrangThai ;
		 public bool TrangThai
			{
			 get 	
				{
					 return this.bool_TrangThai;
				}
			 set 	
				{
					bool_TrangThai=value;
				}
			}
#endregion

		/// <summary>
		/// Inserts a record into the BinhLuan table.
		/// <summary>
		/// <param name="IdBinhLuan"></param>
		/// <param name="IdTinTuc"></param>
		/// <param name="TieuDe"></param>
		/// <param name="TenDayDu"></param>
		/// <param name="Email"></param>
		/// <param name="NoiDung"></param>
		/// <param name="NgayTao"></param>
		/// <param name="TrangThai"></param>
		/// <returns></returns>
		public bool Insert(SqlConnection SqlCnn)
		{
			bool boolInsert = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_BinhLuan_Insert";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdBinhLuan", SqlDbType.Int).Value=IdBinhLuan;
			SqlCmd.Parameters.Add("@IdTinTuc", SqlDbType.Int).Value=IdTinTuc;
			SqlCmd.Parameters.Add("@TieuDe", SqlDbType.NVarChar,50).Value=TieuDe;
			SqlCmd.Parameters.Add("@TenDayDu", SqlDbType.NVarChar,50).Value=TenDayDu;
			SqlCmd.Parameters.Add("@Email", SqlDbType.NVarChar,50).Value=Email;
			SqlCmd.Parameters.Add("@NoiDung", SqlDbType.NText,1073741823).Value=NoiDung;
			SqlCmd.Parameters.Add("@NgayTao", SqlDbType.DateTime).Value=NgayTao;
			SqlCmd.Parameters.Add("@TrangThai", SqlDbType.Bit).Value=TrangThai;

			SqlAdp.InsertCommand = SqlCmd;
			SqlAdp.InsertCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolInsert = true;
			}
			catch
			{
			boolInsert = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolInsert;
		}

		/// <summary>
		/// Selects a single record from the BinhLuan table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable Select(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_BinhLuan_Select";
			SqlCmd.CommandType=CommandType.StoredProcedure;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
		}

		/// <summary>
		/// Selects a single record from the BinhLuan table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable SelectPrimaryKey(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_BinhLuan_SelectPrimaryKey";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdBinhLuan", SqlDbType.Int).Value=IdBinhLuan;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
			}

		/// <summary>
		/// Updates a record in the BinhLuan table.
		/// <summary>
		/// <param name="IdBinhLuan"></param>
		/// <param name="IdTinTuc"></param>
		/// <param name="TieuDe"></param>
		/// <param name="TenDayDu"></param>
		/// <param name="Email"></param>
		/// <param name="NoiDung"></param>
		/// <param name="NgayTao"></param>
		/// <param name="TrangThai"></param>
		public bool Update(SqlConnection SqlCnn)
		{
			bool boolUpdate = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_BinhLuan_Update";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdBinhLuan", SqlDbType.Int).Value=IdBinhLuan;
			SqlCmd.Parameters.Add("@IdTinTuc", SqlDbType.Int).Value=IdTinTuc;
			SqlCmd.Parameters.Add("@TieuDe", SqlDbType.NVarChar,50).Value=TieuDe;
			SqlCmd.Parameters.Add("@TenDayDu", SqlDbType.NVarChar,50).Value=TenDayDu;
			SqlCmd.Parameters.Add("@Email", SqlDbType.NVarChar,50).Value=Email;
			SqlCmd.Parameters.Add("@NoiDung", SqlDbType.NText,1073741823).Value=NoiDung;
			SqlCmd.Parameters.Add("@NgayTao", SqlDbType.DateTime).Value=NgayTao;
            SqlCmd.Parameters.Add("@TrangThai", SqlDbType.Bit).Value = TrangThai;

			SqlAdp.UpdateCommand = SqlCmd;
			SqlAdp.UpdateCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolUpdate = true ;
			}
			catch
			{
			boolUpdate = false ;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolUpdate;
		}

		/// <summary>
		/// Deletes a record from the BinhLuan table by a composite primary key.
		/// <summary>
		public bool Delete(SqlConnection SqlCnn)
		{
			bool boolDelete = false;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_BinhLuan_Delete";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdBinhLuan", SqlDbType.Int).Value=IdBinhLuan;

			SqlAdp.DeleteCommand = SqlCmd;
			SqlAdp.DeleteCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolDelete = true;
			}
			catch
			{
                boolDelete = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolDelete;
			}
	}
 
